package cn.com.bo.util.linux;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.log4j.Logger;

public class ReadCmdLine {  
	
	protected static Logger logger = Logger.getLogger(ReadCmdLine.class);
    
	/**
	 * 在本地上执行shell命令
	 * @param shellString
	 */
	public static void callShell(String shellString) {  
    	logger.info("执行shell命令："+shellString);
        try {  
            Process process = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",shellString});  
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));  
            String line = "";  
            while ((line = input.readLine()) != null) {  
                logger.info(line);  
            }  
            BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));  
            while ((line = error.readLine()) != null) {  
                logger.error(line);  
            } 
            input.close();
            int exitValue = process.waitFor();  
            if (0 != exitValue) {  
            	logger.error("call shell failed. error code is :" + exitValue);  
            } else {
            	logger.info("shell执行成功");
            }
        } catch (Throwable e) {  
        	logger.error("call shell failed. " + e);  
        }  
    }   
} 